package org.gl.training.planner.service;

import java.util.Date;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import org.apache.commons.lang.StringUtils;
import org.gl.training.planner.dao.TaskDao;
import org.gl.training.planner.model.Task;

@ManagedBean(name = "taskBean")
@SessionScoped
public class TaskBean {

	@ManagedProperty(value = "#{taskDao}")
	private TaskDao taskDao;

	private Task task;

	private String fullName;

	private Date date;

	private String errorMessage;

	public String getErrorMessage() {
		return errorMessage;
	}
	
	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public void setTaskDao(TaskDao taskDao) {
		this.taskDao = taskDao;
	}

	public Task getTask() {
		return task;
	}

	public void setTask(Task task) {
		this.task = task;
	}

	public String save() {
		if (StringUtils.isEmpty(task.getEvent())) {
			errorMessage = "Event is empty";
			return null;
		} else if (StringUtils.isEmpty(task.getTime())) {
			errorMessage = "Time is empty";
			return null;
		} else if (StringUtils.isEmpty(task.getEstimateDuration())) {
			errorMessage = "Estimate duration is empty";
			return null;
		}

			taskDao.save(task);
		return "success";
	}

}
